package com.ruoyi.markeing.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.markeing.domain.Free;
import com.ruoyi.markeing.service.IFreeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 免费视频权限设置Controller
 * 
 * @author ruoyi
 * @date 2024-10-28
 */
@RestController
@RequestMapping("/free")
public class FreeController extends BaseController
{
    @Autowired
    private IFreeService freeService;

    /**
     * 查询免费视频权限设置列表
     */
    @RequiresPermissions("free:free:list")
    @GetMapping("/list")
    public TableDataInfo list(Free free)
    {
        startPage();
        List<Free> list = freeService.selectFreeList(free);
        return getDataTable(list);
    }

    /**
     * 导出免费视频权限设置列表
     */
    @RequiresPermissions("free:free:export")
    @Log(title = "免费视频权限设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Free free)
    {
        List<Free> list = freeService.selectFreeList(free);
        ExcelUtil<Free> util = new ExcelUtil<Free>(Free.class);
        util.exportExcel(response, list, "免费视频权限设置数据");
    }

    /**
     * 获取免费视频权限设置详细信息
     */
    @RequiresPermissions("free:free:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(freeService.selectFreeById(id));
    }

    /**
     * 新增免费视频权限设置
     */
    @RequiresPermissions("free:free:add")
    @Log(title = "免费视频权限设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Free free)
    {
        return toAjax(freeService.insertFree(free));
    }

    /**
     * 修改免费视频权限设置
     */
    @RequiresPermissions("free:free:edit")
    @Log(title = "免费视频权限设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Free free)
    {
        return toAjax(freeService.updateFree(free));
    }

    /**
     * 删除免费视频权限设置
     */
    @RequiresPermissions("free:free:remove")
    @Log(title = "免费视频权限设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(freeService.deleteFreeByIds(ids));
    }
}
